package Boundry;

import javax.swing.JTabbedPane;

import Boundry.GenericTools.GenericTabel;
import Boundry.GenericTools.IPanelOperation;
import Boundry.GenericTools.MultiTabbedRequestTableList;
import Boundry.GenericTools.ViewDataPanel;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;

import java.awt.SystemColor;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JScrollBar;

public class InspectorApprovalReqPanel extends ViewDataPanel implements IPanelOperation {

	/**
	 * 
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected int numOfTabs;
	protected JTabbedPane mainTabbedPane;
	protected GenericTabel[] allRequestTableListPanels;
	protected String[] strArrAllRequestsTabsTitle;
	protected boolean[] toBuild;
	protected int startingIndex;
	private JTextField tfInitator;
	private JTextField tfDateOfCreation;
	private JTextField tfIntoSystem;
	private JTextField tfCurrentStep;
	private JTextArea taComments;
	private JButton btnApprove;
	private JButton btnDeny;
	private JPanel datePanel;
	private JLabel lblResone;
	private JTextField tfReason;
	private JTextField tfDays;
	
	public	InspectorApprovalReqPanel(int numOfTabs) throws Exception
	{
		this.numOfTabs = numOfTabs;
		allRequestTableListPanels  = new GenericTabel[ this.numOfTabs];
		toBuild = new boolean[this.numOfTabs];
		strArrAllRequestsTabsTitle = new String[this.numOfTabs];
		mainTabbedPane = new JTabbedPane(JTabbedPane.TOP);
		mainTabbedPane.setBounds(10, 11, 504, 357);
		mainPanel.add(mainTabbedPane);
		    
		    datePanel = new JPanel();
		    datePanel.setBounds(524, 11, 362, 357);
		    mainPanel.add(datePanel);
		    datePanel.setLayout(null);
		    
		    btnApprove = new JButton("Approve");
		    btnApprove.setBounds(238, 308, 114, 38);
		    datePanel.add(btnApprove);
		    
		    btnDeny = new JButton("Deny");
		    btnDeny.setBounds(10, 308, 114, 38);
		    datePanel.add(btnDeny);
		    
		    tfInitator = new JTextField();
		    tfInitator.setEnabled(false);
		    tfInitator.setEditable(false);
		    tfInitator.setColumns(10);
		    tfInitator.setBackground(SystemColor.inactiveCaptionText);
		    tfInitator.setBounds(127, 19, 135, 20);
		    datePanel.add(tfInitator);
		    
		    tfDateOfCreation = new JTextField();
		    tfDateOfCreation.setEnabled(false);
		    tfDateOfCreation.setEditable(false);
		    tfDateOfCreation.setColumns(10);
		    tfDateOfCreation.setBackground(SystemColor.inactiveCaptionText);
		    tfDateOfCreation.setBounds(127, 47, 135, 20);
		    datePanel.add(tfDateOfCreation);
		    
		    JLabel label = new JLabel("Date of creation:");
		    label.setBounds(4, 50, 120, 14);
		    datePanel.add(label);
		    
		    JLabel label_1 = new JLabel("Initiator:");
		    label_1.setBounds(4, 22, 120, 14);
		    datePanel.add(label_1);
		    
		    JLabel label_2 = new JLabel("Info System:");
		    label_2.setBounds(4, 75, 120, 14);
		    datePanel.add(label_2);
		    
		    tfIntoSystem = new JTextField();
		    tfIntoSystem.setEnabled(false);
		    tfIntoSystem.setEditable(false);
		    tfIntoSystem.setColumns(10);
		    tfIntoSystem.setBackground(SystemColor.inactiveCaptionText);
		    tfIntoSystem.setBounds(101, 72, 161, 20);
		    datePanel.add(tfIntoSystem);
		    
		    JLabel lblCurrentStep = new JLabel("Current Step:");
		    lblCurrentStep.setBounds(4, 103, 120, 14);
		    datePanel.add(lblCurrentStep);
		    
		    tfCurrentStep = new JTextField();
		    tfCurrentStep.setEnabled(false);
		    tfCurrentStep.setEditable(false);
		    tfCurrentStep.setColumns(10);
		    tfCurrentStep.setBackground(SystemColor.inactiveCaptionText);
		    tfCurrentStep.setBounds(101, 100, 161, 20);
		    datePanel.add(tfCurrentStep);
		    
		    JLabel lblInspectorComments = new JLabel("Inspector Explanation");
		    lblInspectorComments.setBounds(10, 199, 167, 14);
		    datePanel.add(lblInspectorComments);
		    
		    JScrollPane scrollPane = new JScrollPane();
		    scrollPane.setBounds(10, 224, 342, 52);
		    datePanel.add(scrollPane);
		    
		    taComments = new JTextArea();
		    scrollPane.setViewportView(taComments);
		  
		    datePanel.setBorder(BorderFactory.createTitledBorder( "Inspector Decision"));
		    
		    lblResone = new JLabel("Reason");
		    lblResone.setBounds(4, 128, 120, 14);
		    datePanel.add(lblResone);
		    
		    JScrollPane scrollPane_1 = new JScrollPane();
		    scrollPane_1.setBounds(101, 128, 251, 42);
		    datePanel.add(scrollPane_1);
		    
		    tfReason = new JTextField();
		    scrollPane_1.setViewportView(tfReason);
		    tfReason.setEnabled(false);
		    tfReason.setEditable(false);
		    tfReason.setColumns(10);
		    tfReason.setBackground(SystemColor.inactiveCaptionText);
		    
		    tfDays = new JTextField();
		    tfDays.setEnabled(false);
		    tfDays.setEditable(false);
		    tfDays.setColumns(10);
		    tfDays.setBackground(SystemColor.inactiveCaptionText);
		    tfDays.setBounds(284, 39, 68, 36);
		    datePanel.add(tfDays);
		    
		    JLabel lblDays = new JLabel("Days:");
		    lblDays.setBounds(288, 19, 120, 14);
		    datePanel.add(lblDays);
	    
	}
	
	
	
	
	public void setReason(String tfReason) {
		this.tfReason.setText(tfReason);
	}
	public void setDays(String tfReason) {
		this.tfDays.setText(tfReason);
	}

	
	public String getInspectorExplanation() {
		return taComments.getText();
	}
	public void setInspectorExplanation(String t) {
		 taComments.setText(t);
	}
	public JButton getBtnApprove() {
		return btnApprove;
	}

	public JButton getBtnDeny() {
		return btnDeny;
	}

	public void setInitator(String tfInitator) {
		this.tfInitator.setText(tfInitator);
	}

	public void setDateOfCreation(String tfDateOfCreation) {
		this.tfDateOfCreation.setText( tfDateOfCreation);
	}

	public void setIntoSystem(String tfIntoSystem) {
		this.tfIntoSystem.setText(tfIntoSystem);
	}

	public void setCurrentStep(String tfCurrentStep) {
		this.tfCurrentStep.setText(tfCurrentStep);
	}

	
	 	//Second build all tabs  
	 	
		public void buildTabI(int i,String tabName,String tableBorderName,String[] columnNames, String[][] tableData)
		{
			toBuild[i] = true;
			allRequestTableListPanels[i] = new GenericTabel( 450, 250, tableBorderName);
			allRequestTableListPanels[i].buildTabel(columnNames, tableData);
			strArrAllRequestsTabsTitle[i] = tabName;
			mainTabbedPane.addTab(strArrAllRequestsTabsTitle[i], null, allRequestTableListPanels[i], null);
		}
		
		public int getChooseTab()
		{
			return mainTabbedPane.getSelectedIndex();
		}
	    public boolean isChosen() 
	    {
	    	return allRequestTableListPanels[getChooseTab()].isChosen();
	    }
	    
	    public int getChosen()
	    {
	    	System.out.println("getChooseTab() = " + getChooseTab());
	    	System.out.println("allRequestTableListPanels[getChooseTab()].getTable().getSelectedRow(); = " + allRequestTableListPanels[getChooseTab()].getTable().getSelectedRow());
	    	return allRequestTableListPanels[getChooseTab()].getTable().getSelectedRow(); 
	    }

	    public ListSelectionModel getCellSelectionModel(int i) {
			return allRequestTableListPanels[i].getCellSelectionModel();
		}
	    public void removeRow(int rowLineNumber)
		{
	    	allRequestTableListPanels[getChooseTab()].removeRow(rowLineNumber);
		}

	@Override
	public String apHelpButton() {
 		return "Here the inspector can choose to approve or deny time extension and time estimations";
	}

	@Override
	public String setTitle() {
		return "Approve / Deny time requests";
		 
	}
}
